package edu.xmut.yuepai.common.result;


import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import static edu.xmut.yuepai.common.result.RCode.ERROR;
import static edu.xmut.yuepai.common.result.RCode.SUCCESS;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class R<T> {
    private Integer code;
    private String message;
    private T data;

    public static <T> R<T> ok() {
        return new R<T>(SUCCESS, "success", null);
    }

    public static <T> R<T> ok(Integer code, String message, T data) {
        return new R<T>(code, message, data);
    }

    public static <T> R<T> ok(T data) {
        return new R<T>(SUCCESS, "success", data);
    }

    public static <T> R<T> fail(Integer code, String message) {
        return new R<T>(code, message, null);
    }

    public static <T> R<T> fail(String message) {
        return new R<T>(ERROR, message, null);
    }
}
